/*******************************************************************************
*  file    : settingsdialog.cpp
*  created : 18.08.2013
*  author  : Slyshyk Oleksiy (alexSlyshyk@gmail.com)
*******************************************************************************/

#include <QSettings>
#include "smssettingsdialog.hpp"
#include "ui_smssettingsdialog.h"
#include "rpcclient.hpp"

SmsSettingsDialog::SmsSettingsDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::smsSettingsDialog)
{
    ui->setupUi(this);

    QSettings s;
    s.beginGroup("xml-rpc");
    this->ui->serverAddress->setText (s.value("server", QStringLiteral("127.0.0.1")).toString());
    this->ui->serverPort   ->setValue(s.value("port"  , 8080                       ).toUInt());
    s.endGroup();

    connect(this, SIGNAL(settingsChanged()), RpcClient::instance(), SLOT(loadSettings())  );
}

SmsSettingsDialog::~SmsSettingsDialog()
{
    delete ui;
}

void SmsSettingsDialog::accept()
{

    {
        QSettings s;
        s.beginGroup("xml-rpc");
        s.setValue("server", ui->serverAddress->text());
        s.setValue("port"  , ui->serverPort   ->text());
        s.endGroup();
    }
    emit settingsChanged();

    QDialog::accept();
}
